<template>
  <div>
    <el-form ref="formRef" v-if="formModel" :model="formModel" label-width="120px" class="dialog-form" label-position="right" status-icon>
      <el-form-item label="订单号:">
        <el-input disabled v-model.trim="formModel.orderNo" class="input-item" clearable></el-input>
      </el-form-item>
      <el-form-item label="网点名称:">
        <el-input disabled v-model.trim="formModel.ssmName" class="input-item" clearable></el-input>
      </el-form-item>
      <el-form-item label="网点地址:">
        <el-input disabled v-model.trim="formModel.ssmAddress" class="input-item" clearable></el-input>
      </el-form-item>
      <el-form-item label="支付状态:">
        <el-input disabled v-model.trim="formModel.payStatusStr" class="input-item" clearable></el-input>
      </el-form-item>
      <el-form-item label="支付时间:" v-if="formModel.payStatus != '0'">
        <el-input disabled v-model.trim="formModel.paymentTime" class="input-item" clearable></el-input>
      </el-form-item>
      <el-form-item label="退款状态:" v-if="formModel.refundStatus == 0">
        <el-input disabled value="未退款" class="input-item" clearable />
      </el-form-item>
      <el-form-item label="退款状态:" v-if="formModel.refundStatus == 1">
        <el-input disabled value="待处理" class="input-item" clearable />
      </el-form-item>
      <el-form-item label="退款状态:" v-if="formModel.refundStatus == 2">
        <el-input disabled value="退款中" class="input-item" clearable />
      </el-form-item>
      <el-form-item label="退款状态:" v-if="formModel.refundStatus == 3">
        <el-input disabled value="已退款" class="input-item" clearable />
      </el-form-item>
      <el-form-item label="退款状态:" v-if="formModel.refundStatus == 4">
        <el-input disabled value="已拒绝" class="input-item" clearable />
      </el-form-item>
      <el-form-item label="退款时间:" v-if="formModel.refundTime">
        <el-input disabled v-model.trim="formModel.refundTime" class="input-item" clearable />
      </el-form-item>
      <el-form-item label="用户评论:">
        <span v-if="!review">暂无评论</span>
        <el-input v-else type="textarea" autosize disabled v-model.trim="review.content" class="input-item" clearable></el-input>
      </el-form-item>
      <el-form-item label="" v-if="review">
        <el-button @click="updateReview(review)">{{ reviewBtn }}</el-button>
      </el-form-item>
    </el-form>
    <div v-else>暂无数据</div>
  </div>
</template>

<script>
import { omsQueryReviewInfoApi, omsUpdateReviewInfoApi } from '@/api/omsApi'
export default {
  props: {
    initData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      formModel: null,
      review: '',
      reviewBtn: '隐藏评论',
      reviewFlag: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    /*
     * 查询表格列表数据
     */
    fetchData() {
      // this.isLoading = true
      this.initData.payStatusStr = this.initData.payStatus == '0' ? '未支付' : '已支付'

      this.formModel = this.initData
      console.log('59====', this.formModel)
      omsQueryReviewInfoApi({
        orderNo: this.initData.orderNo
        // orderNo: '440300-00000001-WASH-1722396774046'
      }).then(res => {
        console.log('62====', res)
        this.isLoading = false
        this.review = res.data
        console.log(this.review)
        if (res.data) {
          if (res.data.delFlag == 0) {
            this.reviewBtn = '隐藏评论'
          } else {
            this.reviewBtn = '显示评论'
          }
        }
      })
    },
    updateReview(json) {
      console.log('103===', json)
      if (this.reviewFlag) {
        return
      }
      this.reviewFlag = true
      omsUpdateReviewInfoApi({
        id: json.id,
        delFlag: json.delFlag == '0' ? '1' : '0'
      }).then(res => {
        console.log('107====', res)
        this.fetchData()
        this.reviewFlag = false
        if (json.delFlag == '0') {
          this.$message({
            message: '隐藏成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '显示成功',
            type: 'success'
          })
        }
      })
    }
  }
}
</script>
